﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Sector7.Framework.Core;
using Sector7.Framework.Enums;

namespace Sector7.Medical.Windows
{
    /// <summary>
    /// AddModeWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AddModeWindow : AddModeWindowBase
    {
        #region Accessor
        /// <summary>
        /// 获取或设置窗口实体信息
        /// </summary>
        public override object Entity
        {
            get { return m_control.Entity; }
            set { m_control.Entity = value; }
        }
        #endregion

        #region Public functions
        /// <summary>
        /// 初始化窗口
        /// </summary>
        /// <param name="crud">窗口操作类型</param>
        public override void InitializeWindow(CrudType crud)
        {
            m_control.InitializeControl(crud);
            base.InitializeWindow(crud);
        }

        /// <summary>
        /// 获取数据改变量
        /// </summary>
        /// <param name="primaryKey">主键属性名称</param>
        /// <param name="isChanged">返回是否有改变量</param>
        /// <returns>数据改变量</returns>
        public override EntityDeltaBase GetDelta(string primaryKey, ref bool isChanged)
        {
            return m_control.GetDelta(primaryKey, ref isChanged);
        }
        #endregion

        #region Private functions
        protected override void InitializeForUpdating() { }

        protected override void InitializeForOthers()
        {
            base.InitializeForOthers();

            this.Width = m_control.Width + BORDER_WIDTH;
            this.Height = m_control.Height + BORDER_HEIGHT;
            grdMain.Children.Add(m_control);

            this.Title = m_control.Tag.ToString();
        }

        private void Control_AddSuccess(object sender, EventArgs e)
        {
            AddData();
        }

        private void Control_ClickCancel(object sender, EventArgs e)
        {
            DoCancel();
        }
        #endregion

        #region Structure
        /// <summary>
        /// 创建添加模式窗口对象
        /// </summary>
        /// <param name="control">填充窗口控件</param>
        public AddModeWindow(AddModeControlBase control)
        {
            InitializeComponent();

            m_control = control;
            m_control.ClickCancel += new EventHandler(Control_ClickCancel);
            m_control.AddSuccess += new EventHandler(Control_AddSuccess);
        }
        #endregion

        #region Inner members
        private AddModeControlBase m_control = null;

        private const int BORDER_WIDTH = 10;
        private const int BORDER_HEIGHT = 30;
        #endregion
    }
}
